/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28779
 * Date: 2023-09-13
 * Time: 16:28
 */
//饿汉模式
class Singleton {
    private static Singleton instance = new Singleton();

    //private用来限制代码，禁止别人去 new 实例.
    private Singleton(){}

    public static Singleton getInstance() {
        return instance;
    }
}
public class Demo3 {
    public static void main(String[] args) {
        Singleton s1 = Singleton.getInstance();
        Singleton s2 = Singleton.getInstance();
        //Singleton s3 = new Singleton();



        System.out.println(s1 == s2);
        //System.out.println(s1 == s3);
    }
}
